home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 1993 May / Info-Mac_II_May_1993.to_.sit / Info-Mac II (May 1993).toast / Unix / ps2eps-13.shar < prev    next >
Internet Message Format  |  1993-03-27  |  48KB

  1. Date: Tue, 26 Jan 93 15:19:07 EST 
  2. From: george@mech.seas.upenn.edu (George Jefferson)
  3. Subject: ps2eps-mac 
  4.  
  5.  
  6. this is version 1.3 of my ( unix based ) package for converting
  7. postscript -> mac format eps with screen preview.
  8.  
  9. new features include:
  10. 1 major bug fix. ( would crash when converting large images )
  11. color support ( off by default, to reduce file size )
  12. robust recognition of all sorts of wierd bounding box
  13.  line formats ( atend, decimal numbers, etc )
  14. more informative ( imho ) error reporting.
  15. pbmtoepsi.c is now included in this distribution.
  16.  ( still needs pbmplus to compile though )
  17. unix "man" page
  18.  
  19. requires ghostscript, and the pbmplus package.
  20.  
  21. george jefferson
  22. george@mech.seas.upenn.edu
  23.  
  24. for the archivists, replaces  mac/util/unix/ps2eps1.1.shar @umich
  25.                               info-mac/unix/ps2eps-11.shar @sumex
  26.  
  27. BTW, the name ps2eps is already taken ( by several programs, sigh )
  28. if ps2eps-mac1.3.shar is too long, go with
  29. ps2epsmac13.shar or ps2epsmac13.sh or ps2mac13.sh
  30.  
  31. thanks.
  32.  
  33. ---------ps2eps-mac1.3.shar----cut here---
  34. #! /bin/sh
  35. # This is a shell archive, meaning:
  36. # 1. Remove everything above the #! /bin/sh line.
  37. # 2. Save the resulting text in a file.
  38. # 3. Execute the file with /bin/sh (not csh) to create the files:
  39. #    README
  40. #    ps2eps-mac
  41. #    ps-pict2macb.c
  42. #    makefile
  43. #    test.ps
  44. #    er_echo.c
  45. #    st_echo
  46. #    ps2eps-mac.m
  47. #    pbmtoepsi.c
  48. #    test.eps.bin.uu
  49. # This archive created: Thu Jun 11 10:40:57 1992
  50. export PATH; PATH=/bin:$PATH
  51. if test -f 'README'
  52. then
  53.     echo shar: will not over-write existing file "'README'"
  54. else
  55. cat << \SHAR_EOF > 'README'
  56.  
  57. ps2eps-mac takes an arbitrary postscript file
  58. ( even sort of works with macintosh laserwriter driver dumps.. )
  59. and creates an 'encapsulated postscript with embedded pict' file in
  60. macbinary format.
  61. This file can be included in certain programs ( eg Word5 ) that support
  62. the format, and you will get a 72dpi screen preview image, but postscript
  63. quality output on your postscript printer.
  64. Note that there is no way to represent multi page documents using 
  65. the embeded pict format.
  66.  
  67. so far it has been used sucessfully with
  68. MSWord 5 and its 'draw' module ( does _not_ work with MSW4 or lower )
  69. OzTeX
  70. Kalidagraph
  71. a short list, sigh -- anything else?
  72.  
  73. to make use of this program you need ghostscript and pbmplus
  74.  
  75. ..and you need to know how to transfer a macbinary file to your macintosh
  76.  in a nutshell -- set your unix transfer program to 'binary' and your
  77.  macintosh transfer program to 'macbinary'
  78.  
  79. quick and dirty usage is simply
  80. ps2eps-mac file.ps
  81. -which produces file.eps.bin
  82. -which when transferred to your mac will be named "file.eps"
  83. by default this will be a Word5 file, double clicking on this file will 
  84. open it in word5, with a nice screen image.
  85.  
  86. You can easily change the type/creator by setting shell variables
  87. so that the eps file will open in your favorite eps compatible program.
  88.  
  89. notes-----------
  90. usage 
  91.    ps2eps-mac [ options ] file.ps
  92. options can be any of..
  93.  -q -> quiet mode, overwrites scratch files without asking
  94.  -batch -> same as -q
  95.  -d -> where to put the output file, can be "stdout" to pipe output
  96.        to stdout ( automatically sets "-q" and sends errors to a log file )
  97.  -pipe, eqivalent to "-d stdout"
  98.  -log logfile -> send output messages to logfile
  99.  -debug n -> change debug level to n
  100.  -widen n or -widen unset -> override default widenbox value
  101.  
  102. environment variables
  103. setenv EPSTYPE EPSF
  104. setenv EPSCREATOR MSWD
  105. to set the type and creator of the macintosh file
  106. the defaults are EPSF,MSWD which let me double click
  107. to open the file in MSWord 5, the defaults are defined in ps-pict2macbin.c
  108.  
  109. be sure that the following are on your path, or are in the
  110.  $ps2epsdir directory list
  111.  
  112. ps-pict2macbin
  113. er_echo  <well, you could live without this..>
  114.  ( in the ps2eps-mac shell archive )
  115.  
  116. pnmcrop _or_ pnmcut  < pnmcut works better i think, get both if you can >
  117. pbmtoepsi                      
  118. ppmtopict                      
  119.  ( export.lcs.mit.edu ; contrib/pbm* )
  120.  
  121. gs                             
  122.  ( prep.ai.mit.edu ; pub/gnu/ghost* ) 
  123.  
  124. macps
  125.  ( sumex-aim.stanford.edu ; info-mac/unix )
  126.  macps is needed if the original ps file is a macintosh
  127.  laserwriter driver dump
  128.  
  129. acknowledgements  -- in addition to the above programs, I learned a lot
  130. ( and maybe borrowed some code.. ) from 
  131.  
  132. mcvert
  133. macbin
  134. ps2epsf  Doug Crabill may notice that this shell script bears some
  135.          resemblence to his script ( which creates a pc compatable file )
  136.  
  137. the man page was contributed by jc@msc.edu
  138.  
  139. known bugs
  140.  
  141. translating line endings with tr is bound to mess up any binary stuff
  142.  in the source postscript  -- try playing with the translate options
  143.  if someone knows a foolproof way to do line ending translation,
  144.  please give me a call...
  145.  
  146. explination of options that can be set in the ps2eps-mac script 
  147. { for csh novices...
  148.   a shell variable can be 'set'
  149.   set x
  150.   or set to a value
  151.   set x = 1
  152.   or set to a list
  153.   set x = ( 1 A 4.5 )
  154.   the line,
  155.   #set x
  156.   is commented out, thus ( unless previously set ) x is 'unset'
  157.  
  158.   in this program, all of the variables in the options section
  159.   may be 'set' or 'unset'.  Some of them - where indicated -
  160.   must be set to values, if they are set.      }
  161.  
  162. #set ps2epsdir =  ( /usr/new/bin )
  163.  
  164. add directories to your search path.
  165. you might need here the directorys containing 
  166. gs, pbm stuff, the ps-pict2macbin executable
  167.  
  168. line ending translation options -- a concern only if your ps contains
  169. very long lines or binary data ( included fonts and such )
  170.  
  171. #set notranslate
  172.  
  173. leave unix line endings everywhere
  174. notranslate _does_not_work_ with msword. -- does it work with anything???
  175.  
  176. #set notransfile
  177.  
  178. set notranslatefile to put mac line endings on only the first
  179. two lines of the file -- this is a little wierd but it seems
  180. to work.  I am really curious if this is ok with ps interpreters
  181. like freedom of the press.  This 'aint gonna work when the 
  182. existing bounding box is used ( see bbinfo below )
  183.  
  184. #set havemacps
  185.  
  186. uncomment only if you have macps and you might be processing
  187. a mac laserwriter driver generated file ( beware, you are on thin ice.. )
  188. typically your 'eps' file will only print from a mac running a certain
  189. laserwriter driver.
  190.  
  191. #set noshowpage
  192. uncomment to add line to undefine showpage in the postscript [/showpage {} def]
  193. only necessary if..
  194. 1)your ps contains showpage
  195. 2) your mac application doesn't like it ( eg Word )
  196. ..but it should never hurt.. ( yea right )
  197.  
  198. #set density = 72        
  199.  
  200. do not use this -- changing the density changes the _size_ not the
  201. resolution of the pict image , sigh.  If somone 'fixes' ppmtopict to
  202. have a resolution option me and my deskwriter will be greatful.
  203. ( value required, if set )
  204.  
  205. set widenbox = 1
  206.  
  207. the bounding box sometimes chops off edges of picture, this uses a hack to 
  208. widen the bb by $widenbox points 
  209. an error will result if the 'new' bounding box goes beyond the
  210. edge of ghostscripts 'page' -- if your ps draws at the origin then
  211. you cant widen the box ( try using a translate in the source ps )
  212. note -- set widenbox = 0 is not exactly the same as leaving widenbox unset
  213. -- pnmcut is used rather than pnmcrop ( in priciple the same result by a 
  214. different method )
  215. widenbox can now be defined on the command line as well ( see usage )
  216. whatever you do with it here is the default.
  217. ( value required, if set  *integer only* )
  218.  
  219. #set bbinfo
  220.  
  221. with bbinfo not set, use the bounding box in the original ps file
  222. ( if one exists ) -- requires widenbox to be set as well.
  223. bbinfo unset, and widenbox = 0
  224. leaves the postscript 'data fork' completely
  225. original if the original file contains a bounding box.  Of course, if
  226. the existing bounding box is wrong you will get garbage.
  227.  
  228. set widenboxbb = 0
  229.  
  230. if set, widenboxbb overrides widenbox in cases where existing 
  231. bounding box is used ( typically this should be zero I guess. )
  232. widenbox still must be set to something for this to happen.
  233. ie. the default operation is
  234. no bounding box in original file -> calculate a box and widen by 1 point
  235. bounding box in original file -> use it, no modification at all to postscript
  236. ( value required, if set )
  237.  
  238. please inform me, if you have problems with widenbox, as the pnmcrop
  239. method of cropping the pict will be left out of future versions
  240. if it is not needed.
  241.  
  242. set error = er_echo
  243.  
  244. error reporting program, in case the default er_echo does not compile,
  245. there is a csh script st_echo. st_echo does not work with -log or -pipe
  246. ( value required )
  247.  
  248. #set log ps2eps.log
  249.  
  250. direct output to a log file rather than standard error.  This really just
  251. gets passed to $error
  252. can be set with "-log file" on the command line
  253. (value required if set )
  254.  
  255. set debuglev = 1
  256.  
  257. default debug level, passed to $error
  258.  0 -> only fatal error messages
  259.  1 -> lets you know what is going on
  260.  3 -> possably interesting stuff
  261.  4 ( or higher ) -> very verbose
  262. can be overridden with "-debug n" on the command line
  263. (value required if set )
  264.  
  265. #set quiet
  266.  
  267. make "-q" on by default ( overwrites files without asking )
  268. this cannot be overriden on the command line
  269.  
  270. more usage notes are in the shell script 'ps2eps-mac'
  271.  
  272. this shell archive contains
  273. makefile            -- enter 'make' to compile..
  274. ps2eps-mac          -- executable shell script
  275. ps-pict2macbin.c    -- source for macbinary creating utility
  276. test.ps             -- simple test file
  277. test-ex.eps.bin.uu  -- example macbinary, created from test.ps
  278. README              -- this file
  279. er_echo.c           -- error handling c program
  280. pbmtoepsi.c         -- additional pbmplus source
  281. ps2eps-mac.1        -- unix man page 
  282.  
  283. version history
  284. initial release 4/4/92
  285. george jefferson  george@mech.seas.upenn.edu
  286. v.0.1 4/5/92
  287. added options to modify line ending translation in ps2eps-mac script
  288. ( same action by default )
  289. v.0.2 4/5/92
  290. added code to widen the bounding box -- by 1 pt as default
  291. better test.ps
  292. v.0.3 4/6/92 
  293. corrections to documentation
  294. change default file type to EPSF
  295. fixed info header bug
  296. pad resource fork to 128 byte bound ( suntar choked... )
  297. v.0.4
  298. now looks for a bounding box line in the source file and uses it
  299. rather than using ppmtoepsi to calculate..
  300. this feature is 'on' by default  ( see bbinfo option )
  301. explination of most options moved to this file from the shell script
  302. v.0.5
  303. I _think_ the bounding box is now calculated correctly in all cases.
  304. v.0.6
  305. added er_echo.c, which lets me do nice error reporting
  306. ( if er_echo fails to work, it is a bit superfluous, unset $error )
  307. v.0.7
  308. bypass ftime, for sysv machines
  309. v.0.8
  310. more sysv compatabilty modification
  311. shortened ps-pict2macbin.c to ps-pict2macb.c
  312. v.0.9
  313. added pbmtoepsi source to distribution
  314. v.0.91
  315. fixed time() bug which caused crash on sun3's
  316. v.1.0
  317. included st_echo, although i dont know of any problems with er_echo
  318. added man page, now i think we are ready to send to some ftp sites.
  319. v.1.1 
  320. recognises gs2.4 multi-page output, aborts with an apropriate message.
  321. v.1.2
  322. compatability with several different BoundingBox formats
  323. ( atend )
  324. non - integer values
  325. box:x ( no space )
  326. makes sure first line is %!PS-Adobe
  327. even more saninty checking.
  328. repaired major bug in ps-pict2macb.c, which caused mac to crash 
  329.  with large images.
  330. more output options
  331. v.1.3
  332. color support.
  333. fixed ftp output
  334. SHAR_EOF
  335. fi # end of overwriting check
  336. if test -f 'ps2eps-mac'
  337. then
  338.     echo shar: will not over-write existing file "'ps2eps-mac'"
  339. else
  340. cat << \SHAR_EOF > 'ps2eps-mac'
  341. #!/bin/csh -f
  342. #creates a macintosh "postscript with pict preview" file
  343. #in macbinary format. ( transfer to a mac in binary/macbinary enabled mode )
  344. #
  345. ###options, change defaults by uncommenting "#" lines  _SEE_README_
  346. ###_any_ of these options may be 'unset' or commented out
  347. #set ps2epsdir =  ( /usr/new/bin )     # add to search path
  348. #set notranslate           #do not translate any line endings
  349. #set notransfile           #put mac line ending on only first two lines
  350. #set havemacps             #pass through macps if necessary
  351. #set noshowpage            #undefine showpage in eps file
  352. #set density = 72          #dont change this, it doesn't work :-(
  353. set widenbox = 1           #add n points extra white space around image
  354. #set bbinfo                #do not look for existing bounding box
  355. set widenboxbb = 0         #widenbox used when using existing bounding box
  356. set error = er_echo        #turn on error reporting
  357. #set log = ps2eps.log      #write to log rather than stderr
  358. set debuglev = 1           #default debug level ( 0 = none, 5 = all )
  359. #set quiet                  #make -q on by default
  360. ###end of options, end of even mildly interesting notes
  361. set colors = ppm1run
  362. if($?debuglev == 0)set debuglev = 0
  363. set destdir = '.'
  364. while( $#argv >  0  )
  365.  switch ( $1 )
  366.  case -exec
  367.  set destdir = o.command
  368.  set command = "$2"
  369.  shift
  370.  breaksw
  371.  case -widen
  372.   set widenbox = $2
  373.   if( $widenbox == unset )unset widenbox
  374.   shift
  375.  breaksw
  376.  case -8
  377.   set colors = ppm8run
  378.  breaksw
  379.  case -24
  380.   set colors = ppm24run
  381.  breaksw
  382.  case -q
  383.  case -batch
  384.   set quiet
  385.  breaksw
  386.  case -d
  387.   set destdir = $2
  388.   shift
  389.  breaksw
  390.  case -ftp
  391.   set ftp = $2
  392.   shift
  393.   set destdir = o.ftp
  394.  breaksw
  395.  case -pipe
  396.   set destdir = stdout
  397.  case -debug
  398.   set debuglev = $2
  399.   shift
  400.  breaksw
  401.  case -log
  402.   set logfile = $2
  403.   shift
  404.  breaksw
  405.  default
  406.   set source = $1 #full path name of original ps file
  407.  breaksw
  408.  endsw
  409.  shift
  410. end
  411. if( $?source == 0 )then
  412.  echo no input file specified
  413.  exit
  414. else if( ! -f $source )then
  415.  echo $source not found
  416.  exit
  417. else if( `head -1 $source | grep '^%\\!' | wc -l` == 0)then
  418.  echo $source is not  a postscript file
  419.  exit
  420. endif
  421. if( $destdir == stdout )then
  422.  set quiet
  423.  if( $?logfile == 0 )set logfile = ps2eps-mac.log  
  424. endif
  425. if( $?error == 1 && $?logfile == 1 )then
  426.  rm -f $logfile
  427.  set error = ( $error -log $logfile )
  428. endif
  429. if( $?error == 0 )set error = er_echo                 ##debug
  430. if( "`which $error[1] | wc -w`" != 1 )goto errorok              #then     ##debug
  431.  echo error, $error[1] is not on your path
  432.  if( "`which st_echo | wc -w`" != 1 )then
  433.   set error = st_echo 
  434.  else
  435.   echo fatal error, st_echo is not on your path either
  436.   exit
  437.  endif                                                 ##debug
  438. errorok:  #endif
  439. set error = ( $error -off $debuglev )
  440. if( $debuglev >= 4 )then                           ##debug
  441.  $error -level 4 shell variables...         ##debug
  442.  set | $error -cat -level 4                  ##debug
  443.  $error -level 4  environment variables...   ##debug
  444.  printenv | $error -cat -level 4             ##debug
  445.  $error -level 4  directory listing...       ##debug
  446.  /bin/ls -l | $error -cat -level 4           ##debug
  447. endif                                                 ##debug
  448. if( $?ps2epsdir == 1 )then
  449.  set path = ( $ps2epsdir $path )
  450. endif
  451. set psfile =  $source:t #original file without pathname
  452. set name = $psfile:r    #root name ( .ps removed )
  453. $error -level 2  reading $source to create ${name}.eps.bin ##debug
  454. set ppm = ${name}.ppm   #ghostscript output
  455. set eps =  ${name}.eps  #name of mac file to be created
  456. set pict = ${eps}.pict  #pict data output by ppmtopict
  457. set dat = ${eps}.ps     #data fork, %%boundin box added and line ends changed
  458. set bin = ${eps}.bin    #macbinary file
  459. set save = ${pict}-save #temporary copy of original
  460. set fls = (  $eps $ppm $pict $dat $bin $save )
  461. set np = 1
  462. while( -f ${name}.${np}ppm || $np < 4 )
  463.  set fls = (  $fls ${name}.${np}ppm )
  464.  @ np = $np + 1
  465. end
  466. set destroy
  467. foreach i ( $fls )
  468.  if( -f $i )then
  469.   if( $?quiet == 0 )echo $i will be over written or deleted
  470.   set destroy = ( $destroy $i )
  471.  endif
  472. end
  473. set q = y
  474. if( "$destroy" != "" && $?quiet ==  0 )then
  475.  echo -n "continue y/n? "
  476.  set q = $<
  477. endif
  478. if( $q != y )exit
  479. foreach i ( $destroy )
  480.  $error -level 1 removing $i -level 3 "`/bin/ls -l $i`" ##debug
  481.  rm -f $i
  482. end
  483. if( $psfile != $source )cp $source $psfile
  484. if( $?widenbox == 0 || $?bbinfo == 1 )goto nobbox
  485. # do we need to look further than 20 lines?
  486. set bbinfo = `head -20 $psfile | grep '%%BoundingBox:' | head -1 | sed -e 's/%%BoundingBox:/ /'`
  487. if( $#bbinfo ==  0 )goto nobbox
  488. if( `echo $bbinfo | grep atend | wc -l` != 0 )then
  489.  $error -level 1 looking for %%BoundingBox at the end of the file
  490.  set bbinfo = `cat $psfile | grep '%%BoundingBox:' | tail -1 | sed -e 's/%%BoundingBox:/ /'`  
  491.  set append
  492. endif
  493. if( $#bbinfo != 4 )then
  494.  $error -level 1 seems to be a %%BoundingBox line but there is a problem so it will be ignored $bbinfo
  495.  set bbinfo = ( )
  496.  goto nobbox
  497. endif
  498. echo $bbinfo  | grep '\.'
  499. if( `echo $bbinfo | grep '\.' | wc -l` != 0 )then
  500.  $error -level 1 bounding box contains non-integers -- trying to fix
  501.  $error -n -level 2 $bbinfo
  502.  foreach jj ( 1 2 3 4 )
  503.   set ibb = `echo "$bbinfo[$jj] / 1" | bc`
  504.    if( $jj <= 2 )set bbinfo[$jj] = $ibb
  505.    if( $jj >= 3 && $bbinfo[$jj] != $ibb )@ bbinfo[$jj] = $ibb + 1
  506.  end
  507.  set append
  508.  $error -level 2 " to " $bbinfo
  509. endif
  510. $error -level 1  using bounding box information from source file %%BoundingBox: $bbinfo ##debug
  511. if(`head -1 $psfile |egrep '^%\\!PS-Adobe-' |wc -l` == 0 )then
  512. #this is the minimum header required by msword5 ( yes case sensative )
  513.  $error -level 2 "the header on this ( eps ) input file is not quite correct so we will be appending a new one"
  514.  set append
  515. endif
  516. if( $?widenboxbb == 0 )set widenboxbb =  $widenbox
  517. set widenbox = $widenboxbb
  518. if( $widenbox != 0)$error -level 1  widened by $widenbox ##debug
  519. nobbox:
  520. if( $?havemacps == 1 && `grep '%%IncludeProcSet: "(AppleDict md)"' $psfile | wc -l` != 0 )then
  521.  mv $psfile $save
  522.  $error -level 1  running macps on file -- only for ghostscript ##debug
  523.  macps $save > $psfile
  524.  set macpsed
  525. endif
  526. if( $?density == 0 )set density = 72
  527. $error -level 1  running ghostscript.... ##debug
  528. gs -dNODISPLAY pstoppm.ps << DGC | $error -cat -level 3
  529. $density $density ppmsetdensity
  530. ($name) $colors
  531. DGC
  532. if( -f $ppm && ! -z $ppm )goto gsdone #then
  533.  if( -f ${name}.1ppm )then
  534.   set npages = ( ${name}.*ppm )
  535.   $error -level 0 sorry, this file apparently contains $#npages pages
  536.   $error -level 0 you can not create multi page eps-pict files
  537.   rm -f $npages
  538.  else
  539.   $error -level 0 fatal error, no output from ghostscript
  540.   if( $debuglev < 3)$error -level 0 re-run using -debug 3 or higher to see ghostscript errors
  541.  endif
  542.  exit
  543. gsdone: #endif
  544. $error -level 1  ghostscript done ##debug
  545. if ( $?macpsed == 1)mv $save $psfile
  546. set translate =  "tr '\012' '\015'"
  547. if( $?notranslate == 1)set translate = "cat -"
  548. switch ( $?widenbox )
  549.  case 1
  550.   if( $#bbinfo != 4 )then
  551.    if( $colors != ppm1run )goto colorerror
  552.    $error -level 1  getting bounding box info from pbmtoepsi ##debug
  553.    set bbinfo  = ( `pbmtoepsi $ppm | head -2 | tail -1`  )
  554.    $error -level 2 pbmtoepsi says $bbinfo ##debug
  555.    @ bbinfo[3] = $bbinfo[3] - 1   # I think the pbmtoepsi box is 
  556.    @ bbinfo[4] = $bbinfo[4] + 1   # not quite correct   
  557.    $error -level 2  "'fixed' to be " $bbinfo ##debug
  558.    shift bbinfo
  559.    set append
  560.   endif
  561.   while( $widenbox > 0 && ( $bbinfo[1] - $widenbox < 0 || $bbinfo[2] - $widenbox < 0 ) )
  562.    $error -level 1  -n cant widen box by $widenbox ##debug
  563.    @ widenbox = $widenbox - 1
  564.    $error -level 1  .... using $widenbox ##debug
  565.   end
  566.   if( $widenbox > 0 )then
  567.   set append
  568.   $error -level 1  widening bounding box by $widenbox ##debug
  569.   @ bbinfo[1] = $bbinfo[1] - $widenbox
  570.   @ bbinfo[2] = $bbinfo[2] - $widenbox
  571.   @ bbinfo[3] = $bbinfo[3] + $widenbox
  572.   @ bbinfo[4] = $bbinfo[4] + $widenbox
  573.   endif
  574.   if( $?noshowpage == 1 )set append
  575.   if( $?append == 1 )then
  576.    echo "%\!PS-Adobe-2.0 EPSF-1.2" | $translate > $dat
  577.    echo "%%BoundingBox: $bbinfo" | $translate >> $dat
  578.    $error -level 2  will append bounding box info to postscipt ##debug
  579.    if( $?reportheader == 0 )goto norep  #then
  580.     $error -level 0 first two lines of the file should be:
  581.     $error -level 0 "%\!PS-Adobe-2.0 EPSF-1.2"
  582.     $error -level 0 "%%BoundingBox: $bbinfo"
  583.    norep: #endif
  584.   else
  585.    touch $dat
  586.    $error -level 2  postscipt bounding box left alone ##debug
  587.   endif
  588.  breaksw
  589.  default
  590.   if( $colors != ppm1run )goto colorerror
  591.   $error -level 1  writing eps header using pbmtoepsi directly ##debug
  592.   pbmtoepsi $ppm | head -2 | $translate > $dat
  593.   if( $? reportheader == 1 )pbmtoepsi $ppm | head -2 | $error -level 0 -cat
  594.  breaksw
  595. endsw
  596. if( $?noshowpage == 1 )then
  597.  echo "/showpage {} def" | $translate >> $dat
  598.  $error -level 1   "/showpage {} def" added to postscript  ##debug
  599. endif
  600. if( $?notransfile == 1)set translate = "cat -"
  601. if( "$translate" != "cat -")$error -level 1  translating line endings on postscript file ##debug
  602. cat $psfile  | $translate >> $dat
  603. if( $psfile != $source )rm -f $psfile
  604. if( $?widenbox == 1 )then
  605.  @ xwide =  $bbinfo[3] - $bbinfo[1] 
  606.  @ yhi = $bbinfo[4] - $bbinfo[2]
  607.  set xcut = $bbinfo[1]
  608.  @ ycut = - $yhi + $bbinfo[2]
  609.  $error -level 2  pict bounding box $bbinfo                             ##debug
  610.  set bber = "fatal bounding box error"                                  ##debug
  611.  if( $xcut < 0 )set bber = ( $bber ": x = $xcut out of bounds" )        ##debug
  612.  if( $xwide < 8 )set bber = ( $bber ": xwidth = $xwide less than 8 is too small" )  ##debug
  613.  if( $yhi + $ycut > 0 )set bber = ( $bber ": y out of bounds" )         ##debug
  614.  if( $yhi <= 0 )set bber = ( $bber ": height = $yhi is too small" )     ##debug
  615.  if( $#bber == 1 )goto boxok   #then                                    ##debug
  616.   $error -level 0  $bber ; exit                                         ##debug
  617.  boxok: #endif                                                          ##debug
  618.  $error -level 1  writing pict file using pnmcut,ppmtopict              ##debug
  619.  $error -level 2  pnmcut $xcut $ycut $xwide $yhi $ppm                   ##debug
  620.  ( pnmcut $xcut $ycut $xwide $yhi $ppm | ppmtopict - > $pict ) |& \
  621.     $error -cat -level 2
  622. else
  623.  $error -level 1  writing pict file using pnmcrop,ppmtopict             ##debug
  624.  ( pnmcrop $ppm | ppmtopict - > $pict ) |&  $error -cat -level 2
  625. endif
  626. if( ! -f $pict || -z $pict )then
  627. $error -level 0 fatal error pict not created
  628. ls -l $pict $ppm
  629. if( $debuglev < 2)$error -level 0 re-run with \"-debug 2\"
  630. exit
  631. endif
  632. if( $debuglev >= 3)$error -level 3  removing "`/bin/ls -l $ppm`" ##debug
  633. rm -f $ppm
  634. set iftype ifcreator
  635. if( $?EPSTYPE != 0 )then
  636.  set iftype = ( -type $EPSTYPE )
  637. endif
  638. if( $?EPSCREATOR != 0 )then
  639.  set ifcreator = ( -creator $EPSCREATOR )
  640. endif
  641. $error -level 1  writing macbinary file ##debug
  642. ps-pict2macb $eps $iftype $ifcreator |& $error -cat -level 2
  643. if($debuglev >= 3)then ##debug
  644.  $error -level 3  removing "`/bin/ls -l $pict`" ##debug
  645.  $error -level 3  removing "`/bin/ls -l $dat`" ##debug
  646. endif ##debug
  647. rm -f $pict $dat
  648. switch ( $destdir )
  649.  case .
  650.   $error -level 1  macbinary file $bin saved in current directory ##debug
  651.  breaksw
  652.  case stdout
  653.   cat $bin
  654.   if($debuglev >= 3)$error -level 3  removing "`/bin/ls -l $bin`" ##debug
  655.   rm -f $bin
  656.   $error -level 1  macbinary written to stdout          ##debug
  657.  breaksw
  658.  case o.command
  659.   $error -level 2 $command
  660.   $command $bin
  661.   rm -f $bin
  662.  breaksw
  663.  case o.ftp
  664.   echo $ftp
  665.   ftp $ftp << endftp |& $error -cat -level 1
  666.   bin
  667.   quote macb enabled
  668.   put $bin
  669.   ls $name.eps
  670. endftp
  671.   rm -f $bin
  672.  breaksw
  673.  default
  674.   if( -d $destdir && -w $destdir )then
  675.    mv $bin $destdir
  676.    $error -level 1  output macbinary file is $destdir/$bin    ##debug
  677.   else
  678.    $error -level 1 invalid destination directory $destdir macbinary file $bin left in current directory ##debug
  679.   endif
  680.  breaksw
  681. endsw
  682. exit
  683. colorerror:
  684. $error -level 1 warning attempt to create color preview when source
  685. $error -level 1 file has no bounding box.  - running in b/w mode
  686. $error -level 1 to determine a bounding box
  687. $error -level 1 \( you should add the bb by hand to create a color image \)
  688. set colors = ppm1run
  689. set reportheader
  690. goto nobbox
  691. SHAR_EOF
  692. chmod +x 'ps2eps-mac'
  693. fi # end of overwriting check
  694. if test -f 'ps-pict2macb.c'
  695. then
  696.     echo shar: will not over-write existing file "'ps-pict2macb.c'"
  697. else
  698. cat << \SHAR_EOF > 'ps-pict2macb.c'
  699. /*  ps-pict2macbin.c          george jefferson george@mech.seas.upenn.edu  */
  700. /*  initial release 4/4/92                                                 */
  701. /*  usage ps-pict2macbin file [-type TYPE ] [ -creator CREATOR ]           */
  702. /*  combines "file.ps" and "file.pict" to form "file.bin"                  */
  703. /*  file.bin is a macbinary format file, with macintosh name "file"        */
  704. /*  and creation/modification dates set to the current time of             */
  705. /*  day ( anybody care? )                                                  */
  706. /*  if type and creator are not specified, they are set to EPSF and MSWD   */
  707. /*  because _I_ use word5                                                  */
  708. /*  I see no reason to provide options to change the file names,           */
  709. /*  but it could easily be done                                            */
  710. /*  "file.ps" is taken to be the data fork, no assumptions are made here   */
  711. /*  about its format, however it is presumably postscript code -- It seems */
  712. /*  to be necessary to convert line endings to macintosh endings ( ^M )    */
  713. /*  I think it more appropriate to do that conversion externally ( eg tr ) */
  714. /*                                                                         */
  715. /*  "file.pict" is a pict data file, which is massaged into the resource   */
  716. /*  fork  Its format _is_ important here.                                  */
  717. /*  ppmtopict output is assumed, which ( for no apparent reason ) contains */
  718. /*  lots of null bytes prior to the actual data..                          */
  719. /*  ( in other words this program will not work with other types of        */
  720. /*  resources  )                                                           */
  721. /*  the format of the pict resource fork can be found in IM 1, page 128-131*/
  722. /*  many assumptions are 'hard wired' into this program -- eg we have      */
  723. /*  exactly one resource, of type PICT                                     */
  724. /* */
  725. /* It will be painfully obvious that this is the work of a novice C        */
  726. /* programmer, in fact the program is originally done in FORTRAN and (hand)*/
  727. /* converted ( note the lack of struct's and such )                        */
  728. /* anyway, it works on several sun4-ish machines around here, your milage  */
  729. /* may vary */
  730.  
  731.  
  732. #include <stdio.h>
  733. #include <sys/types.h>
  734. #ifdef notimeb
  735. #else
  736. #include <sys/timeb.h>
  737. #endif
  738.  
  739.  
  740. main (argc,argv)
  741.  int argc; char **argv;
  742. {
  743. int i,j,ksize;
  744. unsigned long mtim=0,ctim=0,unixtime,sizef,realsizef;
  745. int ireslength,idatalength,ipad;
  746. FILE *pic,*bin, *ps;
  747. char outname[30],inname[30],word[4],byte[1],zero[1];
  748. char ftyp[4];
  749. char fcrea[4];
  750. char macname[63], basename[30], psname[30], bbuf[128];
  751. extern unsigned long time2mac();
  752. if( argc <= 1 )
  753.   {
  754.     fprintf(stderr,
  755.     "usage ps-pict2macbin.c file.ps [ -type TYPE ][-creator CRTR ]\n");
  756.     exit();
  757.   }
  758. strcpy(basename,argv[1]);
  759. strcpy(inname,basename);strcat(inname,".pict");
  760. strcpy(outname,basename);strcat(outname,".bin");
  761. bzero(macname,63);
  762. strcpy(macname,basename);
  763. strcpy(psname,basename);strcat(psname,".ps");
  764. fprintf(stderr,"opening pict file %s \n",inname);
  765. if( (pic=fopen(inname,"r")) == NULL )
  766.   {fprintf(stderr,"error opening file\n");exit();}
  767. fprintf(stderr,"opening output file %s \n",outname);
  768. if( (bin=fopen(outname,"w")) == NULL )
  769.   {fprintf(stderr,"error opening file\n");exit();}
  770. fprintf(stderr,"opening ps file %s \n",psname);
  771. if( (ps=fopen(psname,"r")) == NULL )
  772.   {fprintf(stderr,"error opening file\n");exit();}
  773. for(i=1;i<=128;i++)write_one(bin,0); /*leave room for info */
  774. /* copy ps file over to binary */
  775.    idatalength=0;i=0;
  776.    while (fread(byte, sizeof(*byte), 1, ps) > 0)
  777.      {
  778.       if(++i==129)i=1;
  779.       ++idatalength;
  780.       fwrite(byte, sizeof(*bbuf), 1, bin);
  781.      }
  782.    fclose(ps);
  783. for(i=i;i<128;i++)write_one(bin,0); /*pad to next 128 byte boundary */
  784. /* write the pict resource from the pict data file */
  785. fread(byte,sizeof(*byte),1,pic);i=1;
  786. while( strlen(byte)==0 ){fread(byte,sizeof(*byte),1,pic);i++;}
  787. ksize=256*ibyte(byte);
  788. fread(byte,sizeof(*byte),1,pic);
  789. ksize=ksize+ibyte(byte); /* length of actual resource data */
  790. sizef=ftell(pic);fseek(pic,0l,2);realsizef=ftell(pic)-i+1;fseek(pic,sizef,0);
  791. if(ksize != realsizef)fprintf(stderr,"real length %i not reported length %i fixing...\n",realsizef,ksize);
  792. ireslength=256+realsizef+4+50; /* total length of resource fork */
  793. write_header(bin,realsizef);
  794. for(i=1;i<=112;i++)write_one(bin,0);
  795. for(i=1;i<=128;i++)write_one(bin,0); /*reserver stuff */
  796. write_four(bin,realsizef); /* length of resource data */
  797. write_two(bin,ksize); /* length of resource data */
  798. for( j=1;j<=realsizef-2;j++){
  799. fread(byte,sizeof(*byte),1,pic);
  800. fwrite(byte,sizeof(*byte),1,bin);
  801. }
  802. /*    resource map    */
  803. write_header(bin,realsizef);/* copy of header */
  804.   write_four(bin,0);write_two(bin,0); /* 6 null bytes ( reserved ) */
  805.   write_two(bin,0); /* attributes*/
  806.   write_two(bin,28); /* offset from beginning of map to type list */
  807.   write_two(bin,28+22); /* beg map to name list */
  808. /* type list */
  809.   write_two(bin,0); /* only one resource type */
  810.   strcpy(word,"PICT");
  811.   fwrite(word,sizeof(word),1,bin);/* resource type */
  812.   write_two(bin,0); /* only one pict */
  813.   write_two(bin,10); /* begining of type list to reference list */
  814. /* reference list */
  815. write_two(bin,256); /* resource id */
  816. write_one(bin,-1);write_one(bin,-1); /* no name for resource */
  817. write_one(bin,0); /* attributes */
  818. write_two(bin,0);write_one(bin,0) ; /* 3 byte offset within resourc */
  819. write_four(bin,0); /* reserved */
  820. /* pad file to nearest 128 byte boundary */
  821. ipad=(ireslength/128+1)*128-ireslength;
  822. for(i=1;i<=ipad;i++)write_one(bin,0); 
  823. /* this is the end of the resource fork, and the end of the file */
  824. /* macbinary info header */
  825. fseek(bin,0l,0);/* rewind so that we can write the info header */
  826. write_one(bin,0); /* zero */
  827. write_one(bin,strlen(macname)); /* length of file name */
  828. fwrite(macname,sizeof(macname),1,bin); /* name padded to 63 bytes */
  829. bcopy("MSWD",fcrea,4);
  830. bcopy("EPSF",ftyp,4);
  831. for( i=1;i<argc;i++ )
  832.   {
  833.     if( strcmp(argv[i],"-type") == 0 )bcopy(argv[++i],ftyp,4);
  834.     if( strcmp(argv[i],"-creator") == 0 )bcopy(argv[++i],fcrea,4);
  835.   }
  836. fwrite(ftyp,sizeof(ftyp),1,bin);/* file type */
  837. fwrite(fcrea,sizeof(fcrea),1,bin);/* file creator */
  838. write_one(bin,1); /* should this be a zero? */
  839. write_one(bin,0);
  840. write_four(bin,0);write_two(bin,0);
  841. write_one(bin,0);
  842. write_one(bin,0);
  843. write_four(bin,idatalength); /* length og data file */
  844. write_four(bin,ireslength); /* length of resource file */
  845. unixtime = time(&unixtime);
  846. ctim=time2mac(unixtime);
  847. write_four(bin,ctim);
  848. write_four(bin,mtim);
  849. /* all done */
  850. }
  851.  
  852. write_header(iu,kbytes)
  853. FILE *iu;int kbytes;
  854. {
  855.   write_four(iu,256);/*c     4 bytes -> length of header+system+application, always 16+112+128=256*/
  856. /*c next four bytes -> length of pict data + header + 4 bytes for size*/
  857.       write_four(iu,256+kbytes+4);
  858. /*c next four -> length of data*/
  859.       write_four(iu,kbytes+4);
  860. /*c next four -> length of map ( always same )*/
  861.       write_four(iu,50);
  862. }
  863.  
  864. write_one(iu,k)
  865. int k ; FILE *iu ;
  866. {
  867.   unsigned char byte[1];
  868.   byte[0]=k;
  869.   fwrite(byte,sizeof(*byte),1,iu);
  870. }
  871.  
  872.  
  873.  
  874.  
  875. ibyte( b )
  876.      char *b;
  877. {
  878.   int ibyte;
  879.   ibyte=b[0];
  880.   if(ibyte < 0 )ibyte=ibyte+256;
  881.   return(ibyte);
  882. }
  883.  
  884.  
  885. write_four(iu,k)
  886. unsigned long k ; FILE *iu ;
  887. {
  888.   int k1,k2,l,n[4];
  889.   unsigned char byte[1];
  890.   n[0]=16777216;n[1]=65536;n[2]=256;n[3]=1;
  891.   k1=0;
  892.   for(l=0;l<4;l++)
  893.     {
  894.       k2=(k-k1)/n[l];
  895.       byte[0]=k2;
  896.       fwrite(byte,sizeof(*byte),1,iu);
  897.       k1=k1+k2*n[l];
  898.     }
  899. }
  900.  
  901. write_two(iu,k)
  902.      int k ; FILE *iu ;
  903. {
  904.   int k1,k2,l,n[2];
  905.   unsigned char byte[1];
  906.   n[0]=256;n[1]=1;
  907.   k1=0;
  908.   for(l=0;l<2;l++)
  909.     {
  910.       k2=(k-k1)/n[l];
  911.       byte[0]=k2;
  912.       fwrite(byte,sizeof(*byte),1,iu);
  913.       k1=k1+k2*n[l];
  914.     }
  915. }
  916.  
  917.  
  918. #ifndef sysv
  919. typedef unsigned long ulong;    /* 4 bytes */ 
  920. #endif
  921.  
  922.  
  923. /* 'borrowed' from mcvert */
  924. /* Convert Unix time (GMT since 1-1-1970) to Mac
  925.                                     time (local since 1-1-1904) */
  926. #define MACTIMEDIFF 0x7c25b080 /* Mac time of 00:00:00 GMT, Jan 1, 1970 */
  927.  
  928. /* Compatibility issues */
  929. #ifdef BSD
  930. #define long2mac (ulong) htonl
  931. #else
  932. #define long2mac
  933. #endif
  934.  
  935. ulong time2mac(time)
  936. ulong time;
  937. {
  938. #ifdef notimeb
  939.   return long2mac( time + MACTIMEDIFF );
  940. #else
  941.   struct timeb tp;
  942.   ftime(&tp);
  943.   return long2mac(time + MACTIMEDIFF
  944.           - 60 * (tp.timezone /*- 60 * tp.dstflag*/));
  945. #endif
  946. }
  947. /* correcting for daylight savings time needs to be improved. */
  948. SHAR_EOF
  949. fi # end of overwriting check
  950. if test -f 'makefile'
  951. then
  952.     echo shar: will not over-write existing file "'makefile'"
  953. else
  954. cat << \SHAR_EOF > 'makefile'
  955. version=1.3
  956. # ccflags:
  957. #  on sysv machines that do not have the timeb struct or ftime()
  958. # -Dnotimeb
  959. #  system v unix
  960. # -Dsysv
  961. # bsd unix
  962. # -DBSD 
  963. # i dont need any flags on my sparc..
  964. ccflags=
  965. #to compile pbmtoepsi here ( rather than properly including it into the
  966. #pbmplus directory ) define the full path to the pbmplus directory
  967. #and run "make pbmtoepsi"
  968. pbmdirectory=/usr/tools/pbmplus
  969. #files to be included in the shell archive by "make shar"
  970. shfiles= README ps2eps-mac ps-pict2macb.c makefile test.ps er_echo.c st_echo ps2eps-mac.m pbmtoepsi.c
  971. #name of the shell archive
  972. archversion=ps2eps-mac${version}.shar
  973.  
  974. all : ps-pict2macb er_echo ; uudecode test.eps.bin.uu
  975. ps-pict2macb : ps-pict2macb.o ; cc  -o ps-pict2macb ps-pict2macb.o
  976.  
  977. er_echo : er_echo.o ; cc  -o er_echo er_echo.o
  978. shar : ${archversion}
  979. update : update${version}.shar
  980. clean : ; rm -f *.o *~ *# *-log *.bin *.ppm *.pict *.eps.* *.uu
  981. ${archversion} : ${shfiles} test.eps.bin ;
  982.     uuencode test.eps.bin test.eps.bin > test.eps.bin.uu
  983.     echo "---------${archversion}----cut here---" > ${archversion}
  984.     shar ${shfiles} test.eps.bin.uu >> ${archversion}
  985. update${version}.shar : ps-pict2macb.c ps2eps-mac ../ps2macchanges ;
  986.     cp ../ps2macchanges update${version}.shar
  987.     echo "--------- update${version}.shar----cut here---" >>update${version}.shar 
  988.     shar ps2eps-mac ps-pict2macb.c >> update${version}.shar
  989. ps-pict2macb.o : ps-pict2macb.c ; cc ${ccflags} -c ps-pict2macb.c
  990. pbmtoepsi : pbmtoepsi.o ; cc -o pbmtoepsi pbmtoepsi.o ${pbmdirectory}/pbm/libpbm.a
  991. # the -Djustbb flag creates a 'crippled' pbmtoepsi which stops after reporting
  992. # the bounding box ( makes it just a little faster )
  993. # remove it if you want to use pbmtoepsi for other things.
  994. pbmtoepsi.o : pbmtoepsi.c ; 
  995.     cc ${ccflags} -Djustbb -I${pbmdirectory} -I${pbmdirectory}/pbm -c pbmtoepsi.c 
  996. er_echo.o : er_echo.c ; cc ${ccflags} -c er_echo.c
  997. test.eps.bin : ps-pict2macb ps2eps-mac test.ps ; ps2eps-mac test.ps
  998. new : ${archversion} ; cp ${archversion} .tmp-${archversion}
  999.     rm -f *
  1000.     mv .tmp-${archversion} ${archversion}
  1001.     sh ${archversion}
  1002. fast : fastps2eps-mac  #removes all debugging code and comments
  1003.                        #saves < 1 second run time, sigh
  1004. fastps2eps-mac : ps2eps-mac ; echo "#!/bin/csh -f" > fastps2eps-mac
  1005.     sed -e '/^.*##debug.*$$/ d' -e '/^#.*/ d' ps2eps-mac >> fastps2eps-mac
  1006.     chmod u+x fastps2eps-mac
  1007.  
  1008.   
  1009.  
  1010. SHAR_EOF
  1011. fi # end of overwriting check
  1012. if test -f 'test.ps'
  1013. then
  1014.     echo shar: will not over-write existing file "'test.ps'"
  1015. else
  1016. cat << \SHAR_EOF > 'test.ps'
  1017. %!
  1018. 100 100 translate
  1019. /l { lineto } def
  1020. 1 1 moveto
  1021. 9 1 l
  1022. 9 9 l
  1023. 1 1 l
  1024. 1 9 l
  1025. 5 13 l
  1026. 9 9 l
  1027. 1 9 l
  1028. 9 1 l
  1029. stroke
  1030.  
  1031.  
  1032. SHAR_EOF
  1033. fi # end of overwriting check
  1034. if test -f 'er_echo.c'
  1035. then
  1036.     echo shar: will not over-write existing file "'er_echo.c'"
  1037. else
  1038. cat << \SHAR_EOF > 'er_echo.c'
  1039. /* er_echo.c      george jefferson george@mech.seas.upenn.edu 4/12/92        */
  1040. /* replacement for the unix standard echo which writes to standard error     */
  1041. /* rather than standard out.                                                 */
  1042. /* i wrote this 'cause brain-dead csh has no way to redirect to stderr, sigh */
  1043. /* if there is a better way ( besides using sh! ) i'd sure like to know..    */
  1044. /* */
  1045. /* accepts a -n flag to suppress a newline, just like the real echo          */
  1046. /* */
  1047. /* creeping featuritis...  the following flags are also recognised           */
  1048. /* */
  1049. /* -cat -> read from standard input, write to standard output                */
  1050. /* */
  1051. /* '-level n` sets the output level to  n ( default 0 )                      */
  1052. /* '-off n`  sets the debug level to n ( default 0 )                         */
  1053. /* output is supressed whenever the 'off' level is lower than t output level */
  1054. /* examples might help....                                                   */
  1055. /* er_echo -off 1 my dog has -level 2 ticks and -level 1 fleas               */
  1056. /* my dog has fleas                                                          */
  1057. /* er_echo -off 2 my dog has -level 2 ticks and -level 1 fleas               */
  1058. /* my dog has ticks and fleas                                                */
  1059. /* if combined with -cat, the _last_ occurance of each of these flags is used*/
  1060. /* */
  1061. /* -log outputfile -> output is _appended_ to outputfile                     */
  1062. /* rather than going to stderr                                               */
  1063. /* multiple -log arguments are processed until a valid one is found          */
  1064. /* eg er_echo "-log /etc/passwd -log a -log b hi"                            */
  1065. /* writes to "a" ( unless u r root! )                                        */
  1066. #include <stdio.h>
  1067. main (argc,argv)
  1068.  int argc; char **argv;
  1069. {
  1070. int i,newline=1,iout=0,cat=0;
  1071. FILE *logfile;
  1072. char *byte[1],debug[3],off[3];
  1073. logfile=stderr;
  1074. for( i = 1 ; i < argc ; i++ )
  1075.   if( strcmp(argv[i],"-log") == 0 && 
  1076.      ( logfile=fopen(argv[++i],"a") ) != NULL )break;
  1077. if( ( logfile ) == NULL )logfile=fopen("/dev/null","a");
  1078.                                      /* we were trying to redirect, I guess */
  1079.                                      /* dont want to see this message */
  1080. strcpy(off,"0");strcpy(debug,"0");
  1081. for( i = 1  ; i < argc ; i++ )
  1082.   {
  1083.     if( strcmp(argv[i],"-cat") == 0 )cat=1;
  1084.     else if(strcmp(argv[i],"-level") == 0 )strcpy(debug,argv[++i]);
  1085.     else if(strcmp(argv[i],"-off") == 0 )strcpy(off,argv[++i]);
  1086.   }
  1087. if( cat == 1 && strcmp(off,debug) >= 0 )  /*write input to output */
  1088.   {
  1089.     while(i=read(0,byte,1) != 0 )
  1090.       {
  1091.     fprintf(logfile,"%s",byte); 
  1092.       }
  1093.     exit(0);
  1094.   }
  1095. else if( cat == 1)  /* just dump input */
  1096.   {
  1097.     while(i=read(0,byte,1) != 0 );  
  1098.     exit(0);
  1099.   }
  1100. else  /* write command line arguments to output */
  1101.   {
  1102.     strcpy(off,"0");strcpy(debug,"0");
  1103.     for( i = 1 ; i < argc ; i++ )
  1104.       {
  1105.         if(strcmp(argv[i],"-n") == 0 )newline=0;
  1106.         else if(strcmp(argv[i],"-off") == 0 )strcpy(off,argv[++i]);
  1107.         else if(strcmp(argv[i],"-level") == 0 )strcpy(debug,argv[++i]);
  1108.         else if(strcmp(argv[i],"-cat") == 0 );
  1109.         else if(strcmp(argv[i],"-log") == 0 )i++;
  1110.         else if(strcmp(off,debug) >= 0 )
  1111.     {
  1112.             if(iout++!=0)fprintf(logfile," ");
  1113.             fprintf(logfile,"%s",argv[i]);
  1114.           }
  1115.       }
  1116.     if(newline != 0 && iout != 0 )fprintf(logfile,"\n");
  1117.     exit(0);
  1118.   }
  1119. }
  1120.  
  1121.  
  1122.                                           
  1123. SHAR_EOF
  1124. fi # end of overwriting check
  1125. if test -f 'st_echo'
  1126. then
  1127.     echo shar: will not over-write existing file "'st_echo'"
  1128. else
  1129. cat << \SHAR_EOF > 'st_echo'
  1130. #!/bin/csh -f
  1131. # see er_echo.c for an explination of usage..
  1132. set off = 0
  1133. set level = 0
  1134. while ( $#argv > 0 )
  1135. switch ( "$1" )
  1136. case -log
  1137. breaksw
  1138. case -level
  1139. set level = $2
  1140. shift
  1141. breaksw
  1142. case -off
  1143. set off = $2
  1144. shift
  1145. breaksw
  1146. case -cat
  1147. set cat
  1148. breaksw
  1149. default
  1150. if( $level <= $off )echo -n "$1 "
  1151. set out
  1152. breaksw
  1153. endsw
  1154. shift
  1155. end
  1156. if( $?out == 1 )echo " "
  1157. if( $?cat == 0)exit
  1158. if( $level <= $off )exec cat -
  1159. exec cat - >/dev/null
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167. SHAR_EOF
  1168. chmod +x 'st_echo'
  1169. fi # end of overwriting check
  1170. if test -f 'ps2eps-mac.m'
  1171. then
  1172.     echo shar: will not over-write existing file "'ps2eps-mac.m'"
  1173. else
  1174. cat << \SHAR_EOF > 'ps2eps-mac.m'
  1175. .TH ps2eps-mac 1 "Thu May 14 1992"
  1176. .SH NAME
  1177. ps2eps-mac \- converts arbitrary single page PostScript images to MacBinary EPS with PICT preview 
  1178. .SH SYNOPSIS
  1179. \fBps2eps-mac
  1180. [ -q | -batch ][ -8 | -24 ]
  1181. [ \-widen \fI<n>\fB | \-widen unset ]
  1182. [ \-debug \fI<level>\fB ]
  1183. [ \-log \fI<logfile>\fB ]
  1184. [ \-d \fI<directory>\fB | \-pipe | \-exec \fI<command>\fB | \-ftp \fI<ip>\fB ]
  1185. \fIfile.ps\fR
  1186. .SH DESCRIPTION
  1187. \fBps2eps-mac\fR Version 1.0 takes an arbitrary PostScript file and
  1188. creates an Encapsulated PostScript file in MacBinary format.
  1189. This EPS file contains an embedded PICT resource which, when read by
  1190. certain Mac programs (for example, MSWord5 and MacDraw Pro), will 
  1191. be displayed on the Mac screen, allowing for easy annotation of the
  1192. image.  When the output is printed, however, the PICT preview bitmap
  1193. will be discarded and the actual, crisp PostScript will be sent to the
  1194. printer instead.
  1195. .LP
  1196. By default, executing the command \fIps2eps-mac file.ps\fR will produce 
  1197. a file named \fIfile.eps.bin\fR.  Transferred to a Mac via ftp (with
  1198. "MacBinary" enabled on the Mac end and "binary" enabled on the UNIX end),
  1199. the file will be re-named \fIfile.eps\fR. 
  1200. .LP
  1201. When converting to MacBinary format, the default file type and file
  1202. creator are listed as \fIEPSF\fR and \fIMSWD\fR, respectively.  This means
  1203. that double-clicking on the \fIfile.eps\fR Mac file will open
  1204. the file with MSWord5.  To change the default file type, set your
  1205. \fBEPSTYPE\fR environment variable before running \fIps2eps-mac\fR; to
  1206. change the default file creator, set \fBEPSCREATOR\fR.
  1207. .SH OPTIONS
  1208. .IP "\fb\-batch" 5
  1209. Do not prompt for approval when overwriting output or scratch files.
  1210. .IP "\fb\-q" 5
  1211. Synonym for -batch
  1212. .IP "\fB\-8" 5
  1213. .IP "\fB\-24" 5
  1214. Generate 8 or 24 bit ( color ) preview image.
  1215. .IP "\fB\-widen \fI<n>\fR" 5
  1216. Set the amount (in points) by which to widen the BoundingBox. If the input
  1217. file already contains a BoundingBox,
  1218. -widen is ignored and the original box is assumed to be correct.
  1219. Default:  1 point.
  1220. .IP "\fB\-widen unset" 5
  1221. Use a simpler method of calculating the BoundingBox.  This disables
  1222. several features including the ability to widen the BoundingBox, and the 
  1223. utilization of existing BoundingBox information.  This option will avoid
  1224. some kinds of errors.
  1225. .IP "\fB\-debug \fI<level>\fR" 5
  1226. Set the level of debug messages, from 0 (none) to 5 (all).  Default:  1.
  1227. .IP "\fB\-log \fI<logfile>\fR" 5
  1228. Set the name of the logfile in which to place debug messages.  Default:
  1229. messages are sent to stderr.
  1230. .SH OUTPUT PROCESSING FLAGS
  1231. These flags are mutually exclusive.  If more than one is used, the last
  1232. one specified on the command line is applied.  Default:  place output in the
  1233. current directory.  None of these options prevents the writing of scratch files
  1234. to the current directory.
  1235. .IP "\fB\-ftp \fI<ip>\fR" 5
  1236. Transfer output to specified ip address via ftp, then delete output.
  1237. Assumes that no password is required to ftp ( see netrc(5) ) and issues
  1238. commands to put NCSA telnet into macbinary mode.
  1239. .IP "\fB\-exec \fI<command>\fR" 5
  1240. Execute  \fI<command>\fR on output file, then delete output.  Multi word commands must be quoted.  Example -exec "sz -b"
  1241. .IP "\fB\-pipe" 5
  1242. Send output macbinary to standard output.  If a logfile name isn't given with the \fB\-log\fR
  1243. option, errors are sent to \fIps2eps-mac.log\fR.
  1244. .IP "\fB\-d \fI<directory>\fR" 5
  1245. Set the name of the directory in which to place the output file. "\fB\-d\fR stdout" is equivalent to \fB\-pipe\fR.
  1246. .SH BUGS
  1247. At the default debug level (1) some errors which result in an EPS file with
  1248. no preview image are not reported.  Debug = 2 may be a better default.
  1249. .LP
  1250. Color images require a %%BoundingBox: line in the source file, and
  1251. cannot be created with \fI-widen unset\fR, or any setting which causes
  1252. pbmtoepsi to run. 24 bit images may be stripped to 8 bit by ppmtopict.
  1253. .LP
  1254. The \fIps2eps-mac\fR script uses \fItr\fR to translate line endings.  This
  1255. is bound to mess up any binary stuff in the source PostScript, such as
  1256. included fonts.  You could try editing the script and playing around with the
  1257. translation options.  If you find a foolproof way to do the line ending
  1258. translation, please send mail to george@mech.seas.upenn.edu.
  1259. .SH AUTHOR
  1260. George Jefferson, george@mech.seas.upenn.edu
  1261.  
  1262. SHAR_EOF
  1263. fi # end of overwriting check
  1264. if test -f 'pbmtoepsi.c'
  1265. then
  1266.     echo shar: will not over-write existing file "'pbmtoepsi.c'"
  1267. else
  1268. cat << \SHAR_EOF > 'pbmtoepsi.c'
  1269. /* pbmtoepsi.c
  1270. **
  1271. **    by Doug Crabill, based heavily on pbmtoascii
  1272. **
  1273. **    Converts a pbm file to an encapsulated PostScript style bitmap.
  1274. **    Note that it does NOT covert the pbm file to PostScript, only to
  1275. **    a bitmap to be added to a piece of PostScript generated elsewhere.
  1276. **
  1277. ** Copyright (C) 1988 by Jef Poskanzer.
  1278. **
  1279. ** Permission to use, copy, modify, and distribute this software and its
  1280. ** documentation for any purpose and without fee is hereby granted, provided
  1281. ** that the above copyright notice appear in all copies and that both that
  1282. ** copyright notice and this permission notice appear in supporting
  1283. ** documentation.  This software is provided "as is" without express or
  1284. ** implied warranty.
  1285. */
  1286. /* modified by george jefferson george@mech.seas.upenn.edu
  1287. ** when compiled with -Djustbb this program quits after reporting
  1288. ** the bounding box information 
  1289. ** i have added exactly three lines, all marked /*jbb*/
  1290. */
  1291.  
  1292. #include "pbm.h"
  1293.  
  1294. #if !defined(MAXINT)
  1295. #define MAXINT (0x7fffffff)
  1296. #endif
  1297.  
  1298. main( argc, argv )
  1299.     int argc;
  1300.     char *argv[];
  1301. {
  1302.     FILE *ifd;
  1303.     register bit **bits;
  1304.     int rows, cols, row, col, tot, count;
  1305.     int top = MAXINT, bottom = -MAXINT, left = MAXINT, right = -MAXINT;
  1306.     
  1307.     pbm_init( &argc, argv );
  1308.     
  1309.     if ( argc > 2 )
  1310.         pm_usage( "[pbmfile]" );
  1311.     
  1312.     if ( argc == 2 )
  1313.         ifd = pm_openr( argv[1] );
  1314.     else
  1315.         ifd = stdin;
  1316.     
  1317.     bits = pbm_readpbm( ifd, &cols, &rows );
  1318.     
  1319.     pm_close( ifd );
  1320.     
  1321.     for (row = 0; row < rows; row++) {
  1322.         for (col = 0; col < cols; col++) {
  1323.             if (bits[row][col] == PBM_BLACK) {
  1324.                 if (row < top) {
  1325.                     top = row;
  1326.                 }
  1327.                 if (row > bottom) {
  1328.                     bottom = row;
  1329.                 }
  1330.                 if (col < left) {
  1331.                     left = col;
  1332.                 }
  1333.                 if (col > right) {
  1334.                     right = col;
  1335.                 }
  1336.             }
  1337.         }
  1338.     }
  1339.  
  1340.     printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
  1341.      printf("%%%%BoundingBox: %d %d %d %d\n", left, rows - bottom, right, rows - top);
  1342. #ifndef justbb
  1343.     printf("%%%%BeginPreview: %d %d 1 %d\n", right - left + 1, bottom - top + 1, bottom - top + 1);
  1344.  
  1345.     for (row = top; row <= bottom; row++) {
  1346.         printf("%% ");
  1347.         count = 0;
  1348.         for (col = left; col <= right; col += 4) {
  1349.             tot = 0;
  1350.             if (bits[row][col] == PBM_BLACK) {
  1351.                 tot += 8;
  1352.             }
  1353.             if (bits[row][col+1] == PBM_BLACK) {
  1354.                 tot += 4;
  1355.             }
  1356.             if (bits[row][col+2] == PBM_BLACK) {
  1357.                 tot += 2;
  1358.             }
  1359.             if (bits[row][col+3] == PBM_BLACK) {
  1360.                 tot++;
  1361.             }
  1362.             printf("%x", tot);
  1363.             count++;
  1364.         }
  1365.         printf((count % 2) == 0 ? "\n" : "0\n");
  1366.     }
  1367.     printf("%%%%EndImage\n");
  1368.     printf("%%%%EndPreview\n");
  1369. #else  justbb
  1370.     printf("%%%%End modified pbmtoepsi header\n"); /*justbb*/
  1371. #endif justbb
  1372.     exit( 0 );
  1373. }
  1374. SHAR_EOF
  1375. fi # end of overwriting check
  1376. if test -f 'test.eps.bin.uu'
  1377. then
  1378.     echo shar: will not over-write existing file "'test.eps.bin.uu'"
  1379. else
  1380. cat << \SHAR_EOF > 'test.eps.bin.uu'
  1381. begin 644 test.eps.bin
  1382. M  AT97-T+F5P<P                                              
  1383. M                          !%4%-&35-71 $               "B   "
  1384. M6*9<WC@                                            E(5!3+4%D
  1385. M;V)E+3(N,"!%4%-&+3$N,@TE)4)O=6YD:6YG0F]X.B Q,# @.3D@,3$Q(#$Q
  1386. M- TE(0TQ,# @,3 P('1R86YS;&%T90TO;"![(&QI;F5T;R!](&1E9@TQ(#$@
  1387. M;6]V971O#3D@,2!L#3D@.2!L#3$@,2!L#3$@.2!L#34@,3,@; TY(#D@; TQ
  1388. M(#D@; TY(#$@; US=')O:V4-#0T                                 
  1389. M                                                            
  1390. M                                   !     B8   $F    ,@      
  1391. M                                                            
  1392. M                                                            
  1393. M                                                            
  1394. M                                                            
  1395. M                                                            
  1396. M                 2(!(@      #P + !$"_PP _____P            L 
  1397. M   /          $ "@      #P + )B "P      #P +            2   
  1398. M $@       @  0 (                          $            !____
  1399. M____       /  L       \ "P   O8!!_T! 0  _ $)_@$#  $! /T!"@(!
  1400. M 0#] 0  _@$) 0$ ^P$"  $!!@ !^    0L" 0  _0$#  $  0P* 0 !  $!
  1401. M  $!  $,!0$  0$  /X! 0 !# 4!  $!  #^ 0$  0P* 0 !  $!  $!  $+
  1402. M @$  /T! P !  $) 0$ ^P$"   !!P !^0 ! 0$"]@$ _P   0    (F   !
  1403. M)@   #(            < #(  %!)0U0    * 0#__P                  
  1404. B                                                
  1405.  
  1406. end
  1407. SHAR_EOF
  1408. fi # end of overwriting check
  1409. #    End of shell archive
  1410. exit 0
  1411.  
  1412.  
  1413.